** Organize data in a format that is ready for grandparent-level analysis.

*******************************************************************************



*************************
** 1990
*************************

***********
** Wave 3
***********

use OldGenParentData1990_w3

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1990_w3 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1990_w3
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1990_w3
drop if _merge==2
drop _merge



recode panel .=1990
save OrganizedOldGenData1990_w3, replace


***********
** Wave 4
***********

use OldGenParentData1990_w4

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1990_w4 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1990_w4
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1990_w4
drop if _merge==2
drop _merge


recode panel .=1990
save OrganizedOldGenData1990_w4, replace



*************************
** 1991
*************************

***********
** Wave 3
***********

use OldGenParentData1991_w3

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1991_w3 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1991_w3
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1991_w3
drop if _merge==2
drop _merge


recode panel .=1991
save OrganizedOldGenData1991_w3, replace


***********
** Wave 7
***********

use OldGenParentData1991_w7

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1991_w7 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1991_w7
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1991_w7
drop if _merge==2
drop _merge


recode panel .=1991
save OrganizedOldGenData1991_w7, replace






*************************
** 1992
*************************

***********
** Wave 4
***********

use OldGenParentData1992_w4

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1992_w4 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1992_w4
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1992_w4
drop if _merge==2
drop _merge


recode panel .=1992
save OrganizedOldGenData1992_w4, replace


***********
** Wave 6
***********

use OldGenParentData1992_w6

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1992_w6 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1992_w6
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1992_w6
drop if _merge==2
drop _merge


recode panel .=1992
save OrganizedOldGenData1992_w6, replace




*************************
** 1993
*************************

***********
** Wave 3
***********

use OldGenParentData1993_w3

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1993_w3 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 suid addid srefmon using MaxMidGenEITC1993_w3
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1993_w3
drop if _merge==2
drop _merge


recode panel .=1993
save OrganizedOldGenData1993_w3, replace


***********
** Wave 6
***********

use OldGenParentData1993_w6

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1993_w6 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 suid addid srefmon using MaxMidGenEITC1993_w6
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1993_w6
drop if _merge==2
drop _merge



recode panel .=1993
save OrganizedOldGenData1993_w6, replace




***********
** Wave 7
***********

use OldGenParentData1993_w7

** Merge in well-being variables
merge m:1 suid entry pnum using WellBeingVars1993_w7
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 suid addid srefmon using MaxMidGenEITC1993_w7
drop if _merge==2
drop _merge
merge m:1 suid addid srefmon using SumMidGenEITC_1993_w7
drop if _merge==2
drop _merge

recode panel .=1993
save OrganizedOldGenData1993_w7, replace


*************************
** 1996
*************************

***********
** Wave 3
***********

use OldGenParentData1996_w3

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars1996_w3 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC1996_w3
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_1996_w3
drop if _merge==2
drop _merge

recode panel .=1996
save OrganizedOldGenData1996_w3, replace


***********
** Wave 6
***********

use OldGenParentData1996_w6

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars1996_w6 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC1996_w6
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_1996_w6
drop if _merge==2
drop _merge



recode panel .=1996
save OrganizedOldGenData1996_w6, replace



***********
** Wave 9
***********

use OldGenParentData1996_w9

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars1996_w9 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC1996_w9
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_1996_w9
drop if _merge==2
drop _merge

recode panel .=1996
save OrganizedOldGenData1996_w9, replace




***********
** Wave 12
***********

use OldGenParentData1996_w12

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars1996_w12 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC1996_w12
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_1996_w12
drop if _merge==2
drop _merge


recode panel .=1996
save OrganizedOldGenData1996_w12, replace


*************************
** 2001
*************************

***********
** Wave 3
***********

use OldGenParentData2001_w3

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2001_w3 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2001_w3
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2001_w3
drop if _merge==2
drop _merge

recode panel .=2001
save OrganizedOldGenData2001_w3, replace


***********
** Wave 6
***********

use OldGenParentData2001_w6

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2001_w6 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2001_w6
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2001_w6
drop if _merge==2
drop _merge



recode panel .=2001
save OrganizedOldGenData2001_w6, replace



***********
** Wave 9
***********

use OldGenParentData2001_w9

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2001_w9 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2001_w9
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2001_w9
drop if _merge==2
drop _merge


recode panel .=2001
save OrganizedOldGenData2001_w9, replace



*************************
** 2004
*************************

***********
** Wave 3
***********

use OldGenParentData2004_w3

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2004_w3 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2004_w3
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2004_w3
drop if _merge==2
drop _merge

recode panel .=2004
save OrganizedOldGenData2004_w3, replace



***********
** Wave 6
***********

use OldGenParentData2004_w6

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2004_w6 
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2004_w6
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2004_w6
drop if _merge==2
drop _merge



recode panel .=2004
save OrganizedOldGenData2004_w6, replace


*************************
** 2008
*************************

***********
** Wave 4
***********

use OldGenParentData2008_w4

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2008_w4
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2008_w4
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2008_w4
drop if _merge==2
drop _merge

recode panel .=2008
save OrganizedOldGenData2008_w4, replace



***********
** Wave 7
***********

use OldGenParentData2008_w7

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2008_w7
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2008_w7
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2008_w7
drop if _merge==2
drop _merge



recode panel .=2008
save OrganizedOldGenData2008_w7, replace



***********
** Wave 10
***********

use OldGenParentData2008_w10
count

** Merge in well-being variables
merge m:1 ssuid epppnum using WellBeingVars2008_w10
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid srefmon using MaxMidGenEITC2008_w10
drop if _merge==2
drop _merge
merge m:1 ssuid srefmon using SumMidGenEITC_2008_w10
drop if _merge==2
drop _merge

recode  panel .=2008
save OrganizedOldGenData2008_w10, replace



****************************
****************************
** 2014
****************************

***********
** Wave 1
***********

use OldGenParentData2014_w1
count

** Merge in well-being variables
merge m:1 ssuid pnum monthcode using WellBeingVars2014_w1
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid monthcode using MaxMidGenEITC2014_w1
drop if _merge==2
drop _merge
merge m:1 ssuid monthcode using SumMidGenEITC_2014_w1
drop if _merge==2
drop _merge



recode  panel .=2014
save OrganizedOldGenData2014_w1, replace



***********
** Wave 2
***********

use OldGenParentData2014_w2
count

** Merge in well-being variables
merge m:1 ssuid pnum monthcode using WellBeingVars2014_w2
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid monthcode using MaxMidGenEITC2014_w2
drop if _merge==2
drop _merge
merge m:1 ssuid monthcode using SumMidGenEITC_2014_w2
drop if _merge==2
drop _merge

*

recode  panel .=2014
save OrganizedOldGenData2014_w2, replace





***********
** Wave 3
***********

use OldGenParentData2014_w3
count

** Merge in well-being variables
merge m:1 ssuid pnum monthcode using WellBeingVars2014_w3
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid monthcode using MaxMidGenEITC2014_w3
drop if _merge==2
drop _merge
merge m:1 ssuid monthcode using SumMidGenEITC_2014_w3
drop if _merge==2
drop _merge



recode  panel .=2014
save OrganizedOldGenData2014_w3, replace





***********
** Wave 4
***********

use OldGenParentData2014_w4
count

** Merge in well-being variables
merge m:1 ssuid pnum monthcode using WellBeingVars2014_w4
drop if _merge==2
drop _merge

** Merge in info about EITC eligibility for middle generation living in same househod
merge m:1 ssuid monthcode using MaxMidGenEITC2014_w4
drop if _merge==2
drop _merge
merge m:1 ssuid monthcode using SumMidGenEITC_2014_w4
drop if _merge==2
drop _merge

*

recode  panel .=2014
save OrganizedOldGenData2014_w4, replace






***********************************************************
***********************************************************

use OrganizedOldGenData1990_w3
append using OrganizedOldGenData1990_w4

append using OrganizedOldGenData1991_w3
append using OrganizedOldGenData1991_w7

append using OrganizedOldGenData1992_w4
append using OrganizedOldGenData1992_w6

append using OrganizedOldGenData1993_w3
append using OrganizedOldGenData1993_w6
append using OrganizedOldGenData1993_w7

append using OrganizedOldGenData1996_w3
append using OrganizedOldGenData1996_w6
append using OrganizedOldGenData1996_w9
append using OrganizedOldGenData1996_w12

append using OrganizedOldGenData2001_w3
append using OrganizedOldGenData2001_w6
append using OrganizedOldGenData2001_w9

append using OrganizedOldGenData2004_w3
append using OrganizedOldGenData2004_w6

append using OrganizedOldGenData2008_w4
append using OrganizedOldGenData2008_w7
append using OrganizedOldGenData2008_w10

append using OrganizedOldGenData2014_w1
append using OrganizedOldGenData2014_w2
append using OrganizedOldGenData2014_w3
append using OrganizedOldGenData2014_w4


recode rhcalyr 90=1990
recode rhcalyr 91=1991
recode rhcalyr 92=1992
recode rhcalyr 93=1993
recode rhcalyr 94=1994
recode rhcalyr 95=1995
replace rhcalyr = 2013 if panel==2014 & swave==1
replace rhcalyr = 2014 if panel==2014 & swave==2
replace rhcalyr = 2015 if panel==2014 & swave==3
replace rhcalyr = 2016 if panel==2014 & swave==4
replace rhcalyr = 2017 if panel==2018

** Should drop cases in which tfipsst code does not uniquely identify state, when the 
** group of states includes some with different EITC parameters
drop if (panel==1990 | panel==1991 | panel==1992 | panel==1993) & (tfipsst==61 | tfipsst==62 | tfipsst==63)
drop if panel==1996 & (tfipsst==61 | tfipsst==62)
drop if panel==2001 & (tfipsst==61 | tfipsst==62)
** For 2014 and later, drop any cases with state identifier indicating Puerto Rico or foreign country
drop if (panel==2014 | panel==2018) & (tfipsst==60 | tfipsst==61)




** Impose a (sensible but arbitrary) minimum age restriction
drop if tage<30


** Person identifer
egen UniquePersonID_p2014andlater = group(panel ssuid pnum)
replace UniquePersonID_p2014andlater = . if (panel==1990 | panel==1991 | panel==1992 | panel==1993 | panel==1996 | panel==2001 | panel==2004 | panel==2008)

egen UniquePersonID_midyears = group(panel ssuid epppnum )
replace UniquePersonID_midyears = . if (panel==1990 | panel==1991 | panel==1992 | panel==1993 | panel==2014 | panel==2018)

egen UniquePersonID_p1993 = group(panel suid entry pnum)
replace UniquePersonID_p1993 = . if (panel==1996 | panel==2001 | panel==2004 | panel==2008 | panel==2014 | panel==2018)

gen temp_UniquePersonID = UniquePersonID_midyears
replace temp_UniquePersonID = UniquePersonID_p1993 if (panel==1990 | panel==1991 | panel==1992 | panel==1993)
replace temp_UniquePersonID = UniquePersonID_p2014andlater if (panel==2014 | panel==2018)

egen GP_UniquePersonID = group(panel temp_UniquePersonID)


** Household identifier

egen later_UniqueHouseholdID = group(panel ssuid )
replace later_UniqueHouseholdID = . if (panel==1990 | panel==1991 | panel==1992 | panel==1993)

egen earlier_UniqueHouseholdID = group(panel suid entry)
replace earlier_UniqueHouseholdID = . if (panel==1996 | panel==2001 | panel==2004 | panel==2008 | panel==2014 | panel==2018)

gen temp_UniqueHouseholdID = later_UniqueHouseholdID
replace temp_UniqueHouseholdID = earlier_UniqueHouseholdID if (panel==1990 | panel==1991 | panel==1992 | panel==1993)

egen GP_UniqueHouseholdID = group(panel temp_UniqueHouseholdID)





** Month-by-month variation is not meaningful for the well-being variables that are asked about longer reference period
** Trim down to one obs per person per swave
duplicates report GP_UniquePersonID
gen uniform_srefmon = srefmon
replace uniform_srefmon = monthcode if (panel==2014 | panel==2018)
sort GP_UniquePersonID swave uniform_srefmon
by GP_UniquePersonID swave: egen min_srefmon = min(uniform_srefmon)
keep if uniform_srefmon==min_srefmon
drop min_srefmon
duplicates report GP_UniquePersonID
duplicates report GP_UniquePersonID swave




gen ExcellentVeryGoodHealth = (ehltstat==1 | ehltstat==2)
replace ExcellentVeryGoodHealth = . if ehltstat==0
replace ExcellentVeryGoodHealth = . if ehltstat==.

gen AgeSq = tage*tage

gen RefPerson=(errp==1 | errp==2)
replace RefPerson = 1 if ((erelrp==1 | erelrp==2) & (panel==2014 | panel==2018))

** With this sample of only old-gen parents in memory, count up if any of the 
** old gen sample members are the reference person, and create an indicator
** for being in a household where the ref person is in the old generation
sort GP_UniqueHouseholdID swave uniform_srefmon
by GP_UniqueHouseholdID swave uniform_srefmon: egen N_OldGenRefPerson=total(RefPerson)
gen OldGenHasRefPerson=(N_OldGenRefPerson>0)

** Reality check: No one should simultaneously have a ref person in old gen
** and a ref person in mid gen
tab OldGenHasRefPerson MidGenHasRefPerson
** There are a few cases, but N is small.  Move on for now.


gen real = 1

replace real = 229.594/255.657 if rhcalyr==2019
replace real = 229.594/251.107 if rhcalyr==2018
replace real = 229.594/245.120 if rhcalyr==2017
replace real = 229.594/240.007 if rhcalyr==2016
replace real = 229.594/237.017 if rhcalyr==2015
replace real = 229.594/236.736 if rhcalyr==2014
replace real = 229.594/232.957 if rhcalyr==2013

replace real = 229.594/229.594 if rhcalyr==2012
replace real = 229.594/224.939 if rhcalyr==2011
replace real = 229.594/218.056 if rhcalyr==2010
replace real = 229.594/214.537 if rhcalyr==2009
replace real = 229.594/215.303 if rhcalyr==2008
replace real = 229.594/207.342 if rhcalyr==2007
replace real = 229.594/201.6 if rhcalyr==2006
replace real = 229.594/195.3 if rhcalyr==2005
replace real = 229.594/188.9 if rhcalyr==2004
replace real = 229.594/184 if rhcalyr==2003
replace real = 229.594/179.9 if rhcalyr==2002
replace real = 229.594/177.1 if rhcalyr==2001
replace real = 229.594/172.2 if rhcalyr==2000
replace real = 229.594/166.6 if rhcalyr==1999
replace real = 229.594/163 if rhcalyr==1998
replace real = 229.594/160.5 if rhcalyr==1997
replace real = 229.594/156.9 if rhcalyr==1996
replace real = 229.594/152.4 if rhcalyr==1995
replace real = 229.594/148.2 if rhcalyr==1994
replace real = 229.594/144.5 if rhcalyr==1993
replace real = 229.594/140.3 if rhcalyr==1992
replace real = 229.594/136.2 if rhcalyr==1991
replace real = 229.594/130.7 if rhcalyr==1990



gen r_DebtAmount = DebtAmount*real
gen ln_r_Debt = ln(1+r_DebtAmount)

gen r_thtotinc = thtotinc*real

gen r_AssetAmount = AssetAmount*real
gen r_CheckingAmount = CheckingAmount*real
gen r_SavingsCheckingA = SavingsCheckingAmount*real

gen ln_r_AssetAmount = ln(1+r_AssetAmount)
gen ln_r_CheckingAmount=ln(1+r_CheckingAmount)
gen ln_r_SavingsChecking = ln(1+r_SavingsCheckingA)




** Create variables that will be helpful in identifying samples for health-related
** regressions and samples for debt-related regressions
gen MissingHealthInfo=(ehltstat==. | ehltstat==0)
gen MissingDebtInfo = (AnyDebt==. | AnyCCDebt==. | ln_r_Debt==. | AnyChecking==. | ln_r_CheckingAmount==.)



** Generate dummy for receiving (own) Social Security income
** Measured with different variables in 1993 panel and in post-93 panels, although
** you have renamed the 1993 socsec variable essself
gen GetOwnSS = (essself==1)
** Need to update for 2014, if you end up using this variable


** For some analysis, it will be useful to identify earliest observation of a given individual
sort GP_UniquePersonID swave
by GP_UniquePersonID: egen min_swave=min(swave)


** Add in info about state-level unemployment, top tax rate, gdp, etc
merge m:1 tfipsst rhcalyr using OrganizedStateControls

tab _merge
keep if _merge==3
drop _merge

gen r_MaxWelf = MaxWelf*real


** You have two ways of aggregating EITC amounts across mid-gen parents in order
** to assign to the old-gen grandparents.  Method #1 is taking the max from the
** mid gen, and Method #2 is summing over all mid-gen mothers, making the assumption
** that each mid-gen mom is in a different tax filing unit. Method #2 results in 
** missing values of the Sum_MaxEITC_MidGenMoms variable whenever there is just a dad
** in the middle generation, no moms. So try a version where you replace missing values
** of Sum_MaxEITC_MidGenMoms with r_MaxEITC_MidGenMax.
gen EITC_v3 = Sum_MaxEITC_MidGenMoms
replace EITC_v3 = r_MaxEITC_MidGenMax if EITC_v3==.

gen ref_EITC_v3 = Sum_ref_MaxEITC_MidGenMoms
replace ref_EITC_v3 = r_ref_MaxEITC_MidGenMax if ref_EITC_v3==.

** Version that uses current-year EITC parameters
gen EITC_cy = Sum_cy_MaxEITC_MidGenMoms
replace EITC_cy = currentyear_r_MaxEITC_MidGenMax if EITC_cy==.

** Version based on simulated EITC measure.  
** NOTE: First need to convert these nominal amounts to real amounts (confusing 
** that you haven't done this in the same place in the files for each EITC measure)
** EITC measures based on legislated maximum benefit amount are already in real
** terms, but the simulated EITC variable is still nominal.  Convert it to real
gen r_taxsim_eic_MidGenMax = taxsim_eic_MidGenMax*real
gen r_Sum_taxsim_eic_MidGenMoms = Sum_taxsim_eic_MidGenMoms*real
gen EITC_sim_v3 = r_Sum_taxsim_eic_MidGenMoms
replace EITC_sim_v3 = r_taxsim_eic_MidGenMax if EITC_sim_v3==. 

** Version based on federal EITC only
gen EITC_FedOnly_v3 = Sum_MaxFedEITC_MidGenMoms
replace EITC_FedOnly_v3 = r_MaxFedEITC_MidGenMax if EITC_FedOnly_v3==.




** Create a dummy equal to one for those who have all the info needed to appear in health regressions
gen InHealthReg =(ehltst~=. & EITC_v3~=. & tage~=. & AgeSq~=. & Female~=. & Married~=. & White~=. & HSGrad~=. & SomeCollege~=. & CollegeGrad~=. &  unemp_rate~=. & r_MaxWelf~=. & state_rate_wages~=. & minwage~=. & gdp~=. & any_w_a_extended~=. & rhcalyr~=. & tfipsst~=.  & MissingHealthInfo==0)

** Create a dummy equal to one for those who have all the info needed to appear in debt regressions
gen InDebtReg =(AnyDebt~=. & EITC_v3~=. & tage~=. & AgeSq~=. & Female~=. & Married~=. & White~=. & HSGrad~=. & SomeCollege~=. & CollegeGrad~=. &  unemp_rate~=. & r_MaxWelf~=. & state_rate_wages~=. & minwage~=. & gdp~=. & any_w_a_extended~=. & rhcalyr~=. & tfipsst~=. & MissingDebtInfo==0)




** It may be useful to identify earliest observation with non-missing health info (and all the other
** info needed to be included in health regression)
gen swave_temp = swave
replace swave_temp = . if MissingHealthInfo==1 | InHealthReg~=1
sort GP_UniquePersonID
by GP_UniquePersonID: egen min_swave_Health = min(swave_temp)
drop swave_temp


** It may be useful to identify earliest observation with non-missing financial info (and all the other
** info needed to be included in financial regressions)
gen swave_temp = swave
replace swave_temp = . if MissingDebtInfo==1 | InDebtReg~=1
sort GP_UniquePersonID
by GP_UniquePersonID: egen min_swave_Debt = min(swave_temp)
drop swave_temp



** Create some interactions that will be useful for heterogeneity analysis
gen Male=(Female==0)
gen Male_EITC = Male*r_MaxEITC_MidGenMax
gen Male_EITC_v3 = Male*EITC_v3
gen Male_EITC_sim_v3 = Male*EITC_sim_v3

gen Married_EITC = Married*r_MaxEITC_MidGenMax
gen Married_EITC_v3 = Married*EITC_v3
gen Married_EITC_sim_v3 = Married*EITC_sim_v3

gen GetOwnSS_EITC = GetOwnSS*r_MaxEITC_MidGenMax
gen GetOwnSS_EITC_v3 = GetOwnSS*EITC_v3
gen GetOwnSS_EITC_sim_v3 = GetOwnSS*EITC_sim_v3

gen White_EITC_v3 = White*EITC_v3
gen White_EITC_sim_v3 = White*EITC_sim_v3

** Possible variation based on whether mid gen includes any single mom?
gen AnySingleMom_EITC_v3 = AnySingleMom*EITC_v3
gen AnySingleMom_sim_v3 = AnySingleMom*EITC_sim_v3

** Note centiles of age as of first included interview
** 25th pctl = 46
** 50th pctl = 54
** 75th pctl = 63

gen AgeGroup2 = (tage>46 & tage<55)
gen AgeGroup3 = (tage>54 & tage<64)
gen AgeGroup4 = (tage>63)

gen Over64 = (tage>64)

gen AgeGroup2_EITC = AgeGroup2*r_MaxEITC_MidGenMax
gen AgeGroup3_EITC = AgeGroup3*r_MaxEITC_MidGenMax
gen AgeGroup4_EITC = AgeGroup4*r_MaxEITC_MidGenMax

gen AgeGroup2_EITC_v3 = AgeGroup2*EITC_v3
gen AgeGroup3_EITC_v3 = AgeGroup3*EITC_v3
gen AgeGroup4_EITC_v3 = AgeGroup4*EITC_v3

gen AgeGroup2_EITC_sim_v3 = AgeGroup2*EITC_sim_v3
gen AgeGroup3_EITC_sim_v3 = AgeGroup3*EITC_sim_v3
gen AgeGroup4_EITC_sim_v3 = AgeGroup4*EITC_sim_v3

gen InFirstHealthReg =(ehltst~=. & EITC_v3~=. & tage~=. & AgeSq~=. & Female~=. & Married~=. & White~=. & HSGrad~=. & SomeCollege~=. & CollegeGrad~=. &  unemp_rate~=. & r_MaxWelf~=. & state_rate_wages~=. & minwage~=. & gdp~=. & any_w_a_extended~=. & rhcalyr~=. & tfipsst~=.  & MissingHealthInfo==0 & swave==min_swave_Health)

gen InFirstDebtReg =(AnyDebt~=. & EITC_v3~=. & tage~=. & AgeSq~=. & Female~=. & Married~=. & White~=. & HSGrad~=. & SomeCollege~=. & CollegeGrad~=. &  unemp_rate~=. & r_MaxWelf~=. & state_rate_wages~=. & minwage~=. & gdp~=. & any_w_a_extended~=. & rhcalyr~=. & tfipsst~=.  & MissingDebtInfo==0 & swave==min_swave_Debt)


gen Annualized_HH_inc = thtotinc*12
gen r_Annualized_HH_inc = real*Annualized_HH_inc


** Use end of EITC phase-out region to determine if HH is income-eligible for EITC
** NOTE: Not totally sure N_PotentialDep is exactly the right count to use here.  It
** aggregates across all parents in the household, when maybe the per-mom or per-parent
** value is the right one to use here.
gen EITC_inc_elig = 0
replace EITC_inc_elig = 1 if rhcalyr==1989 & Annualized_HH_inc<19340
replace EITC_inc_elig = 1 if rhcalyr==1990 & Annualized_HH_inc<20264
replace EITC_inc_elig = 1 if rhcalyr==1991 & N_PotentialDep==1 & Annualized_HH_inc<21250
replace EITC_inc_elig = 1 if rhcalyr==1991 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<21250
replace EITC_inc_elig = 1 if rhcalyr==1992 & N_PotentialDep==1 & Annualized_HH_inc<22370
replace EITC_inc_elig = 1 if rhcalyr==1992 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<22370
replace EITC_inc_elig = 1 if rhcalyr==1993 & N_PotentialDep==1 & Annualized_HH_inc<23050
replace EITC_inc_elig = 1 if rhcalyr==1993 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<23050
replace EITC_inc_elig = 1 if rhcalyr==1994 & N_PotentialDep==0 & Annualized_HH_inc<9000
replace EITC_inc_elig = 1 if rhcalyr==1994 & N_PotentialDep==1 & Annualized_HH_inc<23755
replace EITC_inc_elig = 1 if rhcalyr==1994 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<25296
replace EITC_inc_elig = 1 if rhcalyr==1995 & N_PotentialDep==0 & Annualized_HH_inc<9230
replace EITC_inc_elig = 1 if rhcalyr==1995 & N_PotentialDep==1 & Annualized_HH_inc<24396
replace EITC_inc_elig = 1 if rhcalyr==1995 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<26673
replace EITC_inc_elig = 1 if rhcalyr==1996 & N_PotentialDep==0 & Annualized_HH_inc<9500
replace EITC_inc_elig = 1 if rhcalyr==1996 & N_PotentialDep==1 & Annualized_HH_inc<25078
replace EITC_inc_elig = 1 if rhcalyr==1996 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<28495
replace EITC_inc_elig = 1 if rhcalyr==1997 & N_PotentialDep==0 & Annualized_HH_inc<9770
replace EITC_inc_elig = 1 if rhcalyr==1997 & N_PotentialDep==1 & Annualized_HH_inc<25750
replace EITC_inc_elig = 1 if rhcalyr==1997 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<29290
replace EITC_inc_elig = 1 if rhcalyr==1998 & N_PotentialDep==0 & Annualized_HH_inc<10030
replace EITC_inc_elig = 1 if rhcalyr==1998 & N_PotentialDep==1 & Annualized_HH_inc<26473
replace EITC_inc_elig = 1 if rhcalyr==1998 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<30095
replace EITC_inc_elig = 1 if rhcalyr==1999 & N_PotentialDep==0 & Annualized_HH_inc<10200
replace EITC_inc_elig = 1 if rhcalyr==1999 & N_PotentialDep==1 & Annualized_HH_inc<26928
replace EITC_inc_elig = 1 if rhcalyr==1999 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<30580
replace EITC_inc_elig = 1 if rhcalyr==2000 & N_PotentialDep==0 & Annualized_HH_inc<10380
replace EITC_inc_elig = 1 if rhcalyr==2000 & N_PotentialDep==1 & Annualized_HH_inc<27413
replace EITC_inc_elig = 1 if rhcalyr==2000 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<31152
replace EITC_inc_elig = 1 if rhcalyr==2001 & N_PotentialDep==0 & Annualized_HH_inc<10710
replace EITC_inc_elig = 1 if rhcalyr==2001 & N_PotentialDep==1 & Annualized_HH_inc<28281
replace EITC_inc_elig = 1 if rhcalyr==2001 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<32121
replace EITC_inc_elig = 1 if rhcalyr==2002 & N_PotentialDep==0 & Annualized_HH_inc<11060
replace EITC_inc_elig = 1 if rhcalyr==2002 & N_PotentialDep==1 & Annualized_HH_inc<29201
replace EITC_inc_elig = 1 if rhcalyr==2002 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<33178
replace EITC_inc_elig = 1 if rhcalyr==2003 & N_PotentialDep==0 & Annualized_HH_inc<11230
replace EITC_inc_elig = 1 if rhcalyr==2003 & N_PotentialDep==1 & Annualized_HH_inc<29666
replace EITC_inc_elig = 1 if rhcalyr==2003 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<33692
replace EITC_inc_elig = 1 if rhcalyr==2004 & N_PotentialDep==0 & Annualized_HH_inc<11490
replace EITC_inc_elig = 1 if rhcalyr==2004 & N_PotentialDep==1 & Annualized_HH_inc<30338
replace EITC_inc_elig = 1 if rhcalyr==2004 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<34458
replace EITC_inc_elig = 1 if rhcalyr==2005 & N_PotentialDep==0 & Annualized_HH_inc<11750
replace EITC_inc_elig = 1 if rhcalyr==2005 & N_PotentialDep==1 & Annualized_HH_inc<31030
replace EITC_inc_elig = 1 if rhcalyr==2005 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<35263
replace EITC_inc_elig = 1 if rhcalyr==2006 & N_PotentialDep==0 & Annualized_HH_inc<12120
replace EITC_inc_elig = 1 if rhcalyr==2006 & N_PotentialDep==1 & Annualized_HH_inc<32001
replace EITC_inc_elig = 1 if rhcalyr==2006 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<36348
replace EITC_inc_elig = 1 if rhcalyr==2007 & N_PotentialDep==0 & Annualized_HH_inc<12590
replace EITC_inc_elig = 1 if rhcalyr==2007 & N_PotentialDep==1 & Annualized_HH_inc<33241
replace EITC_inc_elig = 1 if rhcalyr==2007 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<37783
replace EITC_inc_elig = 1 if rhcalyr==2008 & N_PotentialDep==0 & Annualized_HH_inc<12880
replace EITC_inc_elig = 1 if rhcalyr==2008 & N_PotentialDep==1 & Annualized_HH_inc<33995
replace EITC_inc_elig = 1 if rhcalyr==2008 & (N_PotentialDep>1 & N_PotentialDep~=.) & Annualized_HH_inc<38646
replace EITC_inc_elig = 1 if rhcalyr==2009 & N_PotentialDep==0 & Annualized_HH_inc<13440
replace EITC_inc_elig = 1 if rhcalyr==2009 & N_PotentialDep==1 & Annualized_HH_inc<35463
replace EITC_inc_elig = 1 if rhcalyr==2009 & N_PotentialDep==2 & Annualized_HH_inc<40295
replace EITC_inc_elig = 1 if rhcalyr==2009 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<43279
replace EITC_inc_elig = 1 if rhcalyr==2010 & N_PotentialDep==0 & Annualized_HH_inc<13460
replace EITC_inc_elig = 1 if rhcalyr==2010 & N_PotentialDep==1 & Annualized_HH_inc<35535
replace EITC_inc_elig = 1 if rhcalyr==2010 & N_PotentialDep==2 & Annualized_HH_inc<40363
replace EITC_inc_elig = 1 if rhcalyr==2010 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<43352
replace EITC_inc_elig = 1 if rhcalyr==2011 & N_PotentialDep==0 & Annualized_HH_inc<13660
replace EITC_inc_elig = 1 if rhcalyr==2011 & N_PotentialDep==1 & Annualized_HH_inc<36052
replace EITC_inc_elig = 1 if rhcalyr==2011 & N_PotentialDep==2 & Annualized_HH_inc<40964
replace EITC_inc_elig = 1 if rhcalyr==2011 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<43998

replace EITC_inc_elig = 1 if rhcalyr==2012 & N_PotentialDep==0 & Annualized_HH_inc<13980
replace EITC_inc_elig = 1 if rhcalyr==2012 & N_PotentialDep==1 & Annualized_HH_inc<36920
replace EITC_inc_elig = 1 if rhcalyr==2012 & N_PotentialDep==2 & Annualized_HH_inc<41952
replace EITC_inc_elig = 1 if rhcalyr==2012 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<45060

replace EITC_inc_elig = 1 if rhcalyr==2013 & N_PotentialDep==0 & Annualized_HH_inc<14340
replace EITC_inc_elig = 1 if rhcalyr==2013 & N_PotentialDep==1 & Annualized_HH_inc<37870
replace EITC_inc_elig = 1 if rhcalyr==2013 & N_PotentialDep==2 & Annualized_HH_inc<43038
replace EITC_inc_elig = 1 if rhcalyr==2013 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<46227

replace EITC_inc_elig = 1 if rhcalyr==2014 & N_PotentialDep==0 & Annualized_HH_inc<14590
replace EITC_inc_elig = 1 if rhcalyr==2014 & N_PotentialDep==1 & Annualized_HH_inc<38511
replace EITC_inc_elig = 1 if rhcalyr==2014 & N_PotentialDep==2 & Annualized_HH_inc<43756
replace EITC_inc_elig = 1 if rhcalyr==2014 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<46997

replace EITC_inc_elig = 1 if rhcalyr==2015 & N_PotentialDep==0 & Annualized_HH_inc<14820
replace EITC_inc_elig = 1 if rhcalyr==2015 & N_PotentialDep==1 & Annualized_HH_inc<39131
replace EITC_inc_elig = 1 if rhcalyr==2015 & N_PotentialDep==2 & Annualized_HH_inc<44454
replace EITC_inc_elig = 1 if rhcalyr==2015 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<47747

replace EITC_inc_elig = 1 if rhcalyr==2016 & N_PotentialDep==0 & Annualized_HH_inc<14880
replace EITC_inc_elig = 1 if rhcalyr==2016 & N_PotentialDep==1 & Annualized_HH_inc<39296
replace EITC_inc_elig = 1 if rhcalyr==2016 & N_PotentialDep==2 & Annualized_HH_inc<44648
replace EITC_inc_elig = 1 if rhcalyr==2016 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<47955

replace EITC_inc_elig = 1 if rhcalyr==2017 & N_PotentialDep==0 & Annualized_HH_inc<15010
replace EITC_inc_elig = 1 if rhcalyr==2017 & N_PotentialDep==1 & Annualized_HH_inc<39617
replace EITC_inc_elig = 1 if rhcalyr==2017 & N_PotentialDep==2 & Annualized_HH_inc<45007
replace EITC_inc_elig = 1 if rhcalyr==2017 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<48340

replace EITC_inc_elig = 1 if rhcalyr==2018 & N_PotentialDep==0 & Annualized_HH_inc<15270
replace EITC_inc_elig = 1 if rhcalyr==2018 & N_PotentialDep==1 & Annualized_HH_inc<40320
replace EITC_inc_elig = 1 if rhcalyr==2018 & N_PotentialDep==2 & Annualized_HH_inc<45802
replace EITC_inc_elig = 1 if rhcalyr==2018 & (N_PotentialDep>3 & N_PotentialDep~=.) & Annualized_HH_inc<49194

gen N_HH_EITC_elig_kids = N_PotentialDep
replace N_HH_EITC_elig_kids = 3 if N_PotentialDep>3 & N_PotentialDep~=.


save OrganizedOldGenData, replace


